const router = require('koa-router')()
const fs = require('fs')
/*
  轮播管理接口
*/
router

// 添加轮播图
.post('/setSlidesShow', async (ctx, next) => {
  let query = ctx.request.body
  try {
    let res = await ctx.db.SlidesShow.create({
      ...query
    })
    ctx.body = { code: 0, message: '添加成功', data: res }
  } catch (error) {
    console.log(error.message)
    ctx.body = { code: 1, message: error.message, data: null }
  }
})

// 删除轮播图
.post('/deleteSlidesShow', async (ctx, next) => {
  let query = ctx.request.body
  try {
    let res = await ctx.db.SlidesShow.deleteOne({
      _id: query.id
    })
    ctx.body = { code: 0, message: '删除成功', data: res }
  } catch (error) {
    console.log(error.message)
    ctx.body = { code: 1, message: error.message, data: null }
  }
})

module.exports = router

